{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "toc": true
   },
   "source": [
    "<h1>大纲<span class=\"tocSkip\"></span></h1>\n",
    "<div class=\"toc\"><ul class=\"toc-item\"><li><span><a href=\"#功能\" data-toc-modified-id=\"功能-1\"><span class=\"toc-item-num\">1&nbsp;&nbsp;</span>功能</a></span></li></ul></div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 功能\n",
    "替换文本文件的前两行的文本信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-05-06T12:47:22.811995Z",
     "start_time": "2018-05-06T12:47:22.804097Z"
    }
   },
   "outputs": [],
   "source": [
    "def format_md(filename='python装饰器-property.md',categories=[],tags=[]):\n",
    "    c = ''\n",
    "    for i in categories:\n",
    "        temp = '  - ' + i + '\\n'\n",
    "        c += temp\n",
    "        \n",
    "    t = ''\n",
    "    for i in tags:\n",
    "        temp = '  - ' + i + '\\n'\n",
    "        t += temp\n",
    "\n",
    "    import time\n",
    "    d = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())\n",
    "        \n",
    "    fill = '''---        \n",
    "title: %s\n",
    "category:\n",
    "%s\n",
    "tags:\n",
    "%s\n",
    "date: %s\n",
    "---\n",
    "'''%(filename,c,t,d)\n",
    "    data = []\n",
    "    with open(filename,'r+') as f:\n",
    "        data = f.readlines()[3:]\n",
    "        \n",
    "    data.insert(0,fill)        \n",
    "    with open(filename,'w') as f:\n",
    "        for i in data:\n",
    "            f.write(i)\n",
    "\n",
    "\n",
    "readmd('python装饰器-property.md',['技术类','python1'],['转时期','oi'])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "conda all lib",
   "language": "python",
   "name": "base"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  },
  "latex_envs": {
   "LaTeX_envs_menu_present": true,
   "autoclose": false,
   "autocomplete": true,
   "bibliofile": "biblio.bib",
   "cite_by": "apalike",
   "current_citInitial": 1,
   "eqLabelWithNumbers": true,
   "eqNumInitial": 1,
   "hotkeys": {
    "equation": "Ctrl-E",
    "itemize": "Ctrl-I"
   },
   "labels_anchors": false,
   "latex_user_defs": false,
   "report_style_numbering": false,
   "user_envs_cfg": false
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "大纲",
   "title_sidebar": "目录",
   "toc_cell": true,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
